﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //创建一个A界面的对象
    awidget = new A_Widget;
    //主界面跳转到A界面
    connect(ui->btn_gotoA_widget, &QPushButton::clicked, this, &Widget::gotoA_widget);
    //主界面处理A界面发来的信号
    connect(awidget, &A_Widget::goto_widget, this, &Widget::A_goto_widget);

    //创建一个B界面的对象
    bwidget = new B_Widget;
    //主界面跳转到B界面
    connect(ui->btn_gotoB_widget, &QPushButton::clicked, this, &Widget::gotoB_widget);
    //主界面处理B界面发来的信号
    connect(bwidget, &B_Widget::goto_widget, this , &Widget::B_goto_widget);

    //A界面跳转到B界面
    connect(awidget, &A_Widget::A_gotoB_widget, this, &Widget::A_gotoB_widget);

    //B界面跳转到A界面
    connect(bwidget, &B_Widget::B_gotoA_widget, this, &Widget::B_gotoA_widget);
}

Widget::~Widget()
{
    delete ui;
}

//主界面跳转到A界面
void Widget::gotoA_widget()
{
    this->hide();
    awidget->show();

}

//处理A界面跳转到主界面的信号
void Widget::A_goto_widget()
{
    awidget->hide();
    this->show();
}

//主界面跳转到B界面
void Widget::gotoB_widget()
{
    this->hide();
    bwidget->show();
}

void Widget::B_goto_widget()
{
    bwidget->hide();
    this->show();
}

void Widget::A_gotoB_widget()
{
    awidget->hide();
    bwidget->show();
}

void Widget::B_gotoA_widget()
{
    bwidget->hide();
    awidget->show();
}
